package com.gs.disk.modules.headImgAndWallper.controller.mobile;

import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.gs.entity.R;
import com.gs.disk.modules.headImgAndWallper.dto.APairResourceDto;
import com.gs.disk.modules.headImgAndWallper.service.mobile.MobileAPairResourceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("wallper/mobile/doubleResource")
@Api(tags = "光速壁纸--资源(套图)")
@ApiSort(3)
public class MobileAPairResourceController {

    @Resource
    private MobileAPairResourceService mobileAPairResourceService;

    @GetMapping("list")
    @ApiOperation("资源列表")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "分类名称", name = "categoryName")
    })
    @Cacheable(value = "aPairResourceList", keyGenerator = "myKeyGenerator")
    public R<Map<String, List<APairResourceDto>>> list(@RequestParam(required = false) String categoryName) {
        Map<String, List<APairResourceDto>> list = mobileAPairResourceService.list(categoryName);
        return R.ok(list);
    }

    @GetMapping("info")
    @ApiOperation("资源详情")
    @Cacheable(value = "aPairResourceInfo", keyGenerator = "myKeyGenerator")
    public R<APairResourceDto> info(Long id) {
        APairResourceDto dto = mobileAPairResourceService.info(id);
        return R.ok(dto);
    }


    @PostMapping("upload")
    @ApiOperation("上传资源")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "套图分类", name = "categoryName"),
            @ApiImplicitParam(value = "头像图片id", name = "headImgId"),
            @ApiImplicitParam(value = "背景图", name = "backgroundImgId"),
            @ApiImplicitParam(value = "签名", name = "keyWord"),
            @ApiImplicitParam(value = "昵称", name = "nickname"),
    })
    public R uploadAPairResource(@RequestParam String categoryName,
                            @RequestParam Long headImgId,
                            @RequestParam Long backgroundImgId,
                            @RequestParam String keyWord,
                            @RequestParam String nickname) {
        mobileAPairResourceService.uploadAPairResource(categoryName, headImgId, backgroundImgId, keyWord, nickname);
        return R.ok();
    }
}
